package com.xlabs.client.Elements;

import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.Label;

/**
 * TextLink class.
 *
 * @author albitagh
 */
public class TextLink extends Label {

    /**
     * enabled ?
     */
    boolean enabled = true;

    /**
     * Initializes TextLink.
     */
    public TextLink() {
        super();
        init();
    }

    /**
     * Initializes TextLink with an element.
     * @param element
     */
    public TextLink(Element element) {
        super(element);
        init();
    }

    /**
     * Initialies TextLink.
     * @param text label's text.
     * @param wordWrap wordwrapped ?
     */
    public TextLink(String text, boolean wordWrap) {
        super(text, wordWrap);
        init();
    }

    /**
     * Initializes TextLink.
     * @param text label's text.
     */
    public TextLink(String text) {
        super(text);
        init();
    }

    /**
     * Init.
     */
    private void init() {
        addStyleName("TextLink");
    }

    /**
     * Listener for browser events.
     * @param event browser event.
     */
    @Override
    public void onBrowserEvent(Event event) {
        if (enabled)
            super.onBrowserEvent(event);
    }

    /**
     * Sets enabled.
     * @param enabled enabled ? 
     */
    private void setEnabled(boolean enabled) {
        if (this.enabled == enabled)
            return;
        if (enabled) {
            removeStyleName("TextLink-disabled");
            addStyleName("TextLink");
        } else {
            removeStyleName("TextLink");
            addStyleName("TextLink-disabled");
        }
        this.enabled = enabled;
    }
}